﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace EkspSys.Components
{
    class StringListItem : IListItem
    {
        public delegate void ListItemAction();

        private string txt;
        private ListItemAction action;

        public StringListItem(string txt, ListItemAction action)
        {
            this.txt = txt;
            this.action = action;
        }

        private const int ItemMargin = 5;
        private const float PictureHeight = 25;

        public void Draw(System.Windows.Forms.DrawItemEventArgs e)
        {
            // See if the item is selected.
            Brush br;
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                br = SystemBrushes.HighlightText;
            else
                br = new SolidBrush(e.ForeColor);

            // Draw the background.
            e.DrawBackground();

            Font f = new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold);

            // Draw the text.
            RectangleF layout_rect = new RectangleF(e.Bounds.Left, e.Bounds.Top, e.Bounds.Right - e.Bounds.Left, e.Bounds.Bottom - e.Bounds.Top);
            e.Graphics.DrawString(txt, MainWindow.DefaultFont, br, layout_rect);

            // Draw the focus rectangle if appropriate.
            e.DrawFocusRectangle();
        }

        public void PerformAction(MainWindow win)
        {
            action();
        }

        public string Text
        {
            get { return txt; }
            set { txt = value; }
        }
    }
}
